<template>
  <div class="login-form-wrapper">
    <a-spin :loading="loading"   dot>
    <div class="login-form-title">Build Quickly</div>
    <a-form :model="formData" class="login-form" layout="vertical" :style="{ width: '600px' }" @submit="submitPost">
      <a-form-item field="name" label="用户名" size="large" :validate-trigger="['change', 'input']">
        <a-input v-model="formData.urUsername" :style="{ width: '320px' }" placeholder="请输入账号"
          allow-clear>
          <template #prefix>
            <icon-user />
          </template>
        </a-input>
      </a-form-item>
      <a-form-item field="post" label="密码" szie="large" :validate-trigger="['change', 'input']">
        <a-input-password v-model="formData.urPassword" :style="{ width: '320px' }" placeholder="请输入密码"
          allow-clear>
          <template #prefix>
            <icon-lock />
          </template>
        </a-input-password>
      </a-form-item>
      <a-form-item field="yzm" label="验证码" szie="large" :style="{ width: '320px' }">
        <a-input v-model="formData.captcha" placeholder="请输入验证码" allow-clear />
        <a-image @click="getCaptcha" width="80px" heigh="20px" :src="imgData.captcha" :show-loader="true"
          :preview="false" />
      </a-form-item>

      <a-form-item>
        <a-button html-type="submit" type="primary" :style="{ width: '320px' }">登录</a-button>
      </a-form-item>
    </a-form>
    </a-spin>
  </div>
</template>

<script>
import api from '@/api/sys/index';
import { setToken, checkIp } from '@/utils/auth';
export default {
  data() {
    return {
      formData: {
        urUsername: '',
        urPassword: '',
        captcha: '',
        codeEncryption: '',
      },
      imgData: '',
      loading:false
    };
  },
  created() {
    checkIp()
    this.getCaptcha();
  },
  methods: {
    getCaptcha() {
      api.getCaptcha().then((res) => {
        this.imgData = res.data.data;
        this.formData.codeEncryption = this.imgData.codeEncryption;
      });
    },
    submitPost() {
      if (
        this.formData.urUsername === '' ||
        this.formData.urUsername === ' ' ||
        this.formData.urPassword === '' ||
        this.formData.urUsername === ' '
      ) {
        this.$message.info('请检查账号密码是否输入！');
        return;
      }
       this.loading=true
      api.login(this.formData).then((res) => {
       // console.log(res.data.data);
        if (res.data.code === 200) {
          //  setUserId(res.data.data.user.urId);
          localStorage.setItem("userName", res.data.data.userName)
          localStorage.setItem("urAvatar", res.data.data.urAvatar)
          localStorage.setItem("user", JSON.stringify(res.data.data.user))
          setToken(res.data.data.token.tokenValue);
          const path = this.$route.query.redirect;
          const pathUrl = path;
          if (pathUrl !== undefined) this.$router.push({ name: pathUrl });
          else this.$router.push('/dashboard/workplace');
        } else {
          this.getCaptcha()
          this.$message.info(res.data.data.msg);
        }
        this.loading=false
      });
    },
  },
};
</script>
<style scoped></style>
<style lang="less" scoped>
::v-deep(.arco-spin-mask){
   width: 320px !important;
   border-radius: 20px !important;
}
// ::deep(.arco-spin-mask){
//    border-radius: 20px !important;
// }
.login-form-title {
  transform: translateY(-50PX);
  background: linear-gradient(to left, #007AFF, #5856D6);
  -webkit-background-clip: text; /* 让背景渐变应用到文字上 */
  color: transparent !important; /* 文字本身的颜色设置为透明 */
}
.login-form {
  &-wrapper {
    width: 320px;
  }

  &-title {
    color: var(--color-text-1);
    font-weight: 500;
    font-size: 24px;
    line-height: 32px;
  }

  &-sub-title {
    color: var(--color-text-3);
    font-size: 16px;
    line-height: 24px;
  }

  &-error-msg {
    height: 32px;
    color: rgb(var(--red-6));
    line-height: 32px;
  }

  &-password-actions {
    display: flex;
    justify-content: space-between;
  }

  &-register-btn {
    color: var(--color-text-3) !important;
  }
}
</style>
